---@class UIShowManager
UIShowManager = {
    rewards = {}
}
local this = UIShowManager
this.TimeBoxQuickOpenEnum = {
    bagOpen = 1,
    taskOpen = 2,
}
---@param rewards TempItemInfo[]
function UIShowManager.ShowRewardByTempItemInfo(rewards, closeCallback)
    table.clear(this.rewards)
    if rewards then
        for k, v in pairs(rewards) do
            local data = {};
            data["num"] = v.num;
            data["itemModelId"] = v.itemModelId
            table.insert(this.rewards, data)
        end
    end
    showUI(PanelNames.UICommonItemGet, nil, nil, 3, this.rewards, closeCallback)
end
--奖励
---@param rewards {itemModelId:number,num:number}[]
function UIShowManager.ShowReward(rewards, closeCallback,showTipCtrlIndex)
    showUI(PanelNames.UICommonItemGet, nil, nil, 3, rewards, closeCallback,nil, nil,nil,nil,nil,showTipCtrlIndex)
end
---奖励预览
function UIShowManager.ShowRewardPreview(rewards,subStr,closeCallback)
    showUI(PanelNames.UIRewardPreview,rewards,subStr,closeCallback)
end
---奖励预览
function UIShowManager.ShowRewardPreviewByJson(rewardsJson,subStr,closeCallback)
    local tb = decodeJsonStrToTabel(rewardsJson)
    local rewards = {}
    for k, v in pairs(tb) do
        local data = {};
        data["itemModelId"] = v[1]
        data["num"] = v[2]
        table.insert(rewards, data)
    end
    this.ShowRewardPreview(rewards,subStr,closeCallback )
end

---奖励预览
function UIShowManager.ShowRewardPreviewByJson2(rewardsJson, heroRewardJson, subStr,closeCallback)

    local rewards = {}
    local tb1 = decodeJsonStrToTabel(rewardsJson)
    for _, v in pairs(tb1) do
        local data = {};
        data["itemModelId"] = v[1]
        data["num"] = v[2]
        table.insert(rewards, data)
    end 
    local heros = decodeJsonStrToTabel(heroRewardJson)
    if heros ~= nil then
        for _, v in pairs(heros) do
            local data = {} 
            data["itemModelId"] = v[1]
            data["num"] = v[2]
            data["isHero"] = true
            table.insert(rewards, data)
        end
    end
    this.ShowRewardPreview(rewards,subStr,closeCallback)
end

function UIShowManager.ShowRewardByJson(rewardsJson, closeCallback)
    local tb = decodeJsonStrToTabel(rewardsJson)
    local rewards = {}
    for k, v in pairs(tb) do
        local data = {};
        data["itemModelId"] = v[1]
        data["num"] = v[2]
        table.insert(rewards, data)
    end
    showUI(PanelNames.UICommonItemGet, nil, nil, 3, rewards, closeCallback)
end
---时光宝箱快速开启界面
function UIShowManager.ShowTimeBoxQuickOpenInTask(sequence, index)
    showUI(PanelNames.UITimeBoxQuickOpen, this.TimeBoxQuickOpenEnum.taskOpen, sequence, index)
end
---时光宝箱快速开启界面
function UIShowManager.ShowTimeBoxQuickOpenInBag(itemId)
    showUI(PanelNames.UITimeBoxQuickOpen, this.TimeBoxQuickOpenEnum.bagOpen, nil, nil, itemId)
end
---时光宝箱开箱特效
function UIShowManager.ShowTimeBoxOpenEffectView(boxModelId,rewards)
    showUI(PanelNames.UITimeBoxEffectBox, boxModelId,rewards)
end
---时光宝箱选择界面
function UIShowManager.ShowTimeBoxBag(sequence)
    showUI(PanelNames.UITimeBoxBag, sequence)
end
---公告排行榜界面
function UIShowManager.ShowBillboardRank(pageIndex,battleBackFunc)
    showUI(PanelNames.UISystemBillBoard,pageIndex,battleBackFunc)
    --NoticeHandler.ReqSynRankNotice(pageIndex)
end
---雕像排行榜界面
function UIShowManager.ShowRanking(pageIndex)
    HelperFunc.OpenUILoading(function () showUI(PanelNames.UIRanking,pageIndex); end);
    --NoticeHandler.ReqSynRankNotice(pageIndex)
end



function UIShowManager.ShowUISocialRank()
    showUI(PanelNames.UISocialRank)
end
---大秘境排行榜
function UIShowManager.ShowUIMythicRank()
    showUI(PanelNames.UIMythicRank)
end
---爬塔排行榜
function UIShowManager.ShowUITowerRank(type)
    showUI(PanelNames.UIClimbTowerSort, type)
end
--flow tip
local tempTB = {}
function UIShowManager.ShowCommonTips(title, des, story)
    tempTB.title = title;
    tempTB.des = des;
    tempTB.story = story;
    showUI(PanelNames.CommonTips, tempTB);
end

function UIShowManager.ShowCommonTipsById(id)
    if id == nil then
        return;
    end
    tempTB = {};
    tempTB.title = "HelpTitle"..id;
    tempTB.des = "HelpDes"..id;
    showUI(PanelNames.CommonTips, tempTB);
end
---确认取消弹框提示
---subDes 有些界面需要额外小字描述，可不填
function UIShowManager.ShowCommonConfirm(des, subDes, sureCallback, cancelCallback, callbackTable, sureText, cancelText,title,itemId)
    subDes = subDes or ""
    showUI(PanelNames.UIConfirm, des, subDes, sureCallback, cancelCallback, callbackTable, sureText, cancelText,title,itemId)
end
function UIShowManager.ShowCommonPop(id,sureCallback,cancelCallback,closeCallback)
    local pop = CtrlManager.GetCtrl(PanelNames.UICommonPop)
    pop.Init(id, function (flag, isClose)
        if flag then
            if sureCallback then
                sureCallback()
            end
        else
            if isClose and closeCallback then
                closeCallback();
            elseif cancelCallback then
                cancelCallback()
            end
        end
    end)
end
---远征
function UIShowManager.ShowExpeditionView()
    ExpeditionHandler.ReqSynExpedition()
end
function UIShowManager.ShowExpeditionViewImmediate()
    logicMgr.ExpeditionMgr.showExpeditionImmediate = true
    if logicMgr.ExpeditionMgr.isMapView then
        showUI(PanelNames.UIExpeditionMapView)
    else
        showUI(PanelNames.UIExpeditionStageView)
    end
end
---远征关卡弹框
function UIShowManager.ShowExpeditionStagePreview(stageId)
    showUI(PanelNames.UIExpeditionStagePreview, stageId)
end
---远征buff选择
function UIShowManager.ShowExpeditionSelectBuffView(stageId, buffId, callback, callbackTB)
    showUI(PanelNames.UIExpeditionSelectBuff, stageId, buffId, callback, callbackTB)
end
---远征buff查看（女神祝福）
function UIShowManager.ShowExpeditionCarPreview()
    showUI(PanelNames.UIExpeditionCardPreview)
end
function UIShowManager.ShowExpeditionHolyStone(...)
    showUI(PanelNames.UIExpeditionHolyStone, ...)
end
function UIShowManager.ShowExpeditionFinalBossReward(rewards, closeCallback, callbacktb)
    showUI(PanelNames.UIExpeditionFinalBossReward, rewards, closeCallback, callbacktb)
end
function UIShowManager.ShowExpeditionHeroList()
    showUI(PanelNames.UIExpeditionHeroList)
end

function UIShowManager.ShowUIShop(shopType, backFunc,callbackBGM)
    showUI(PanelNames.UIShop, shopType, backFunc,callbackBGM)
end
function UIShowManager.ShowUIStoryMemoryList(id)
    showUI(PanelNames.UIStoryMemoryList, id)
end
function UIShowManager.ShowUIChapterBox(callback)
    showUI(PanelNames.UIChapterBox,callback)
end
local heroItem = {};
function UIShowManager.getTeamHeroItem(teamId, idx, obj)
    teamId = teamId or 1
    if heroItem[teamId] == nil then
        heroItem[teamId] = {}
    end
    local title = heroItem[teamId][idx]
    if  obj ~= nil then
        title = obj:GetChild("title" .. teamId .. idx)
        title.visible = false;
        title.name = "title" .. teamId .. idx;
        heroItem[teamId][idx] = title
    end
    return heroItem[teamId][idx]
end

return UIShowManager